//
//  WWRequestAPI+Lottery.m
//  WangLottery
//
//  Created by 黄修勇 on 12-9-14.
//
//

#import "WWRequestAPI+Lottery.h"

@implementation WWRequestAPI (Lottery)

-(long)getLotteryListWithTarget:(id)target{

    return [self requestWithAction:@"getlotterylist" paras:nil target:target parserSEL:@selector(lotteryDicForString:)];
}
@end


@implementation WWDataParser (LotteryParser)

-(NSDictionary *)lotteryDicForString:(NSString *)string{

    WWDataModel *model=[string parserData];
    if ([model isKindOfClass:[WWDataModel class]]) {
        
    }
    
    return nil;
}

-(NSDictionary *)lotteryDicForString:(NSString *)string keyArray:(NSArray *)keyArray infoKeyArray:(NSArray *)infoKeyArray{

    NSMutableDictionary *lotteryDic=[NSMutableDictionary dictionary];
    
    WWDataModel *model=[string parserData];
    if ([model isKindOfClass:[WWDataModel class]]) {
        NSMutableArray *tempArray=[NSMutableArray array];
        for (int i=0; i<model.dataArray.count; i++) {
            NSString *tempDataString=[model.dataArray objectAtIndex:i];
            NSString *lotteryString=[tempDataString substringWithRange:NSMakeRange(1, tempDataString.length-2)];
            NSArray *lotteryDataArray=[lotteryString componentsSeparatedByString:@","];
            NSMutableDictionary *tempDic=[NSMutableDictionary dictionary];
            for (int j=0; j<keyArray.count; j++) {
                [tempDic setObject:[lotteryDataArray objectAtIndex:j] forKey:[keyArray objectAtIndex:j]];
            }
            
            NSMutableString *lotteryNumber=[NSMutableString string];
            
            for (int j=keyArray.count; j<lotteryDataArray.count; i++) {
                [lotteryNumber appendString:[lotteryDataArray objectAtIndex:j]];
                if (j!=lotteryDataArray.count-1) {
                    [lotteryNumber appendString:@","];
                }
            }
            [tempDic setObject:lotteryNumber forKey:@"number"];
            [tempArray addObject:tempDic];
        }
        NSArray *infoArray=[[model infoString] componentsSeparatedByString:@","];
        
        for (int i=0; i<infoKeyArray.count; i++) {
            [lotteryDic setObject:[infoArray objectAtIndex:i] forKey:[infoKeyArray objectAtIndex:i]];
        }
    }
    
    return [self dicForResult:lotteryDic];
}
@end